package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.AnalysisByDay;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface AnalysisByDayMapper extends BaseMapper<AnalysisByDay> {

    //累计用户数(每天注册数加和)
    @Select("SELECT SUM(num_registered) FROM tb_analysis_by_day")
    Long countRegisterNum();

    //统计一段时间内的活跃用户数
    @Select("SELECT SUM(num_active) FROM tb_analysis_by_day WHERE record_date BETWEEN #{begin} AND #{end}")
    Long countActiveNum(@Param("begin") String begin, @Param("end") String end);

    //查询一段时间内的每日新增,活跃，次日留存率
    //新增用户
    @Select("SELECT SUM(num_registered) FROM `tb_analysis_by_day` WHERE record_date=#{everyDay}")
    Integer findNumRegistered(@Param("everyDay") String everyDay);

    //活跃用户
    @Select("SELECT SUM(num_active) FROM `tb_analysis_by_day` WHERE record_date=#{everyDay}")
    Integer findNumActive(@Param("everyDay") String everyDay);

    //次日留存率
    @Select("SELECT SUM(num_retention1d) FROM `tb_analysis_by_day` WHERE record_date=#{everyDay}")
    Integer findNumRetention1d(@Param("everyDay") String everyDay);
}